package com.easyfun.healthmagicbox.comm.json;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.easyfun.healthmagicbox.pojo.DoctorProfile;

public class DoctorProfileListJsonWrapper<T extends JsonWrapper> extends
		AbstractListJsonWrapper<T, DoctorProfile> {

	public DoctorProfileListJsonWrapper() {
		super();
	}

	public DoctorProfileListJsonWrapper(List<DoctorProfile> pps) {
		super(pps);
	}

	public void deserializeFromObj(JSONObject obj) throws JSONException {

		DoctorProfileJsonWrapper<?, ?> leafwrapper;
		try {
			leafwrapper = DoctorProfileJsonWrapper.getInstance(
					obj.getJSONObject("DoctorProfile"),
					DoctorProfileJsonWrapper.class);

			mpps.add(leafwrapper.getDataPojo());
		} catch (InstantiationException e) {
			e.printStackTrace();
			throw new JSONException(e.toString());
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			throw new JSONException(e.toString());
		}

	}

	public JSONObject serializeToObj() throws JSONException {
		JSONObject serializedObj = new JSONObject();

		int i = 0;
		for (DoctorProfile pp : mpps) {
			DoctorProfileJsonWrapper<?, ?> leafwrapper = new DoctorProfileJsonWrapper(
					pp);
			serializedObj.put(String.valueOf(i), leafwrapper.serialize());
			i++;
		}

		return serializedObj;
	}

}
